package com.poobo.dao.impl;

import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.poobo.base.impl.BaseDaoImpl;
import com.poobo.dao.ISysLogDao;
import com.poobo.entity.TbSysLog;
import com.poobo.util.pager.Page;
import com.poobo.util.str.StrUtil;


@Repository
public class SysLoginDaoImpl extends BaseDaoImpl implements ISysLogDao {

	@Override
	public void saveSysLog(TbSysLog tbSysLog) {
		saveOrUpdate(tbSysLog);
	}

	@Override
	public Page getTbSysLog(TbSysLog sysLog,Page page) {
		String baseHql = "from TbSysLog where 1=1 ";
		String countHql = "select count(*) from TbSysLog where 1=1 ";
		StringBuffer where = new StringBuffer();
		List<Object> params = new ArrayList<Object>();
		String orderBy = " order by id desc";
		if( !StrUtil.isEmpty(sysLog.getAcitionLoginName()) && sysLog.getAcitionLoginName() != "" ){
			where.append(" and acitionLoginName like ? ");
			params.add("%" + sysLog.getAcitionLoginName() + "%");
		}
		if( !StrUtil.isEmpty(sysLog.getMthodDesc()) && sysLog.getMthodDesc() != "" ){
			where.append(" and mthodDesc like ? ");
			params.add("%" + sysLog.getMthodDesc() + "%");
		}
		page.setBaseHql(baseHql + where.toString() + orderBy);
		page.setCountHql(countHql + where.toString());
		page.setParam(params);
		return getPageByHql(page);
	}

	@Override
	public void deleteBySysLogId(Integer sysLogId) {
		String hql = " delete from TbSysLog where id = "+ sysLogId +" ";
		delObjectByIds(hql);
	}

}
